//https://leetcode.cn/problems/zigzag-conversion/

class Solution {
public:
    string convert(string s, int numRows) {
        if (numRows == 1)
            return s;

        int d = 2 * numRows - 2;
        string ret;
        //第一行
        for (int i = 0; i < s.size(); i += d)
        {
            ret += s[i];
        }

        //中间行
        for (int k = 1; k < numRows - 1; k++)
        {
            for (int i = k, j = d - k; i < s.size() || j < s.size(); i += d, j += d)
            {
                if (i < s.size()) ret += s[i];
                if (j < s.size()) ret += s[j];
            }
        }

        //最后一行
        for (int i = numRows - 1; i < s.size(); i += d)
        {
            ret += s[i];
        }

        return ret;

    }
};